package com.roomaja.roomaja.mapper;

import com.roomaja.roomaja.entity.WenKuLabelEntity;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by 15361 on 2018/4/30.
 */
@Repository
@Mapper
public interface WenKuLabelEntityMapper{

    @Insert("insert into wenku_label(label_id,label_name) values (#{labelId}, #{labelName})  on duplicate key update label_id = #{labelId}")
    void insert(WenKuLabelEntity wenKuLabelEntity);

    @Select({"select label_id, label_name from wenku_label where label_id = #{labelId} limit 1"})
    @Results({
            @Result(id=true,column="label_id",property="labelId"),
            @Result(column="label_name",property="labelName"),
    })
    WenKuLabelEntity findByLabelId(String labelId);

    @Select({"select label_id, label_name from wenku_label order by  RAND() limit #{n}"})
    @Results({
            @Result(id=true,column="label_id",property="labelId"),
            @Result(column="label_name",property="labelName"),
    })
    //随机取n条数据
    List<WenKuLabelEntity> getDataByRand(int n);
}
